<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="里程数" prop="addName">
        <el-input
          v-model="queryParams.addName"
          placeholder="请输入里程数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入市"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区" prop="district">
        <el-input
          v-model="queryParams.district"
          placeholder="请输入区"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在高速" prop="street">
        <el-input
          v-model="queryParams.street"
          placeholder="请输入所在高速"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在高速" prop="area">
        <el-input
          v-model="queryParams.area"
          placeholder="请输入所在高速"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公里数" prop="kilometers">
        <el-input
          v-model="queryParams.kilometers"
          placeholder="请输入公里数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="高速" prop="speed">
        <el-input
          v-model="queryParams.speed"
          placeholder="请输入高速"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="高速编号" prop="road">
        <el-input
          v-model="queryParams.road"
          placeholder="请输入高速编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manage:locationAll:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manage:locationAll:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manage:locationAll:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manage:locationAll:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="locationAllList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="里程数" align="center" prop="addName" />
      <el-table-column label="经度" align="center" prop="longNumber" />
      <el-table-column label="维度" align="center" prop="latNumber" />
      <el-table-column label="市" align="center" prop="city" />
      <el-table-column label="区" align="center" prop="district" />
      <el-table-column label="所在高速" align="center" prop="street" />
      <el-table-column label="详细位置" align="center" prop="addr" />
      <el-table-column label="详细地址" align="center" prop="locationdescribe" />
      <el-table-column label="标记号" align="center" prop="countNumber" />
      <el-table-column label="标记" align="center" prop="countFlag" />
      <el-table-column label="所在辖区" align="center" prop="area" />
      <el-table-column label="公里数" align="center" prop="kilometers" />
      <el-table-column label="高速" align="center" prop="speed" />
      <el-table-column label="高速编号" align="center" prop="road" />
      <el-table-column label="报警电话" align="center" prop="tel" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manage:locationAll:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manage:locationAll:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改定位信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body class="addeditbox">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="里程数" prop="addName">
          <el-input v-model="form.addName" placeholder="请输入里程数" />
        </el-form-item>
        <el-form-item label="经度" prop="longNumber">
          <el-input v-model="form.longNumber" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="维度" prop="latNumber">
          <el-input v-model="form.latNumber" placeholder="请输入维度" />
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-input v-model="form.city" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="区" prop="district">
          <el-input v-model="form.district" placeholder="请输入区" />
        </el-form-item>
        <el-form-item label="所在高速" prop="street">
          <el-input v-model="form.street" placeholder="请输入所在高速" />
        </el-form-item>
        <el-form-item label="详细位置" prop="addr">
          <el-input v-model="form.addr" placeholder="请输入详细位置" />
        </el-form-item>
        <el-form-item label="详细地址" prop="locationdescribe">
          <el-input v-model="form.locationdescribe" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="标记号" prop="countNumber">
          <el-input v-model="form.countNumber" placeholder="请输入标记号" />
        </el-form-item>
        <el-form-item label="标记" prop="countFlag">
          <el-input v-model="form.countFlag" placeholder="请输入标记" />
        </el-form-item>
        <el-form-item label="标记" prop="area">
          <el-input v-model="form.area" placeholder="请输入标记" />
        </el-form-item>
        <el-form-item label="公里数" prop="kilometers">
          <el-input v-model="form.kilometers" placeholder="请输入公里数" />
        </el-form-item>
        <el-form-item label="高速" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入高速" />
        </el-form-item>
        <el-form-item label="高速编号" prop="road">
          <el-input v-model="form.road" placeholder="请输入高速编号" />
        </el-form-item>
        <el-form-item label="报警电话" prop="tel">
          <el-input v-model="form.tel" placeholder="请输入报警电话" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLocationAll, getLocationAll, delLocationAll, addLocationAll, updateLocationAll, exportLocationAll } from "@/api/manage/locationAll";

export default {
  name: "LocationAll",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 定位信息表格数据
      locationAllList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        addName: null,
        city: null,
        district: null,
        street: null,
        area: null,
        kilometers: null,
        speed: null,
        road: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询定位信息列表 */
    getList() {
      this.loading = true;
      listLocationAll(this.queryParams).then(response => {
        this.locationAllList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        addName: null,
        longNumber: null,
        latNumber: null,
        city: null,
        district: null,
        street: null,
        addr: null,
        locationdescribe: null,
        countNumber: null,
        countFlag: null,
        createTime: null,
        area: null,
        kilometers: null,
        speed: null,
        road: null,
        tel: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加定位信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLocationAll(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改定位信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLocationAll(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLocationAll(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除定位信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLocationAll(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有定位信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportLocationAll(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
<style>
	.addeditbox .el-form-item{
		width: 48%;
		display: inline-block;
	}
	.addeditbox .el-form-item__content{
		width: calc(100% - 100px);
	}
	.addeditbox .el-select,.el-select--medium{
		width: 100%;
	}
	.location .el-form-item__content{
		width: calc(100% - 115px);
	}
	.el-dialog__body {
    padding: 30px 20px 0;
	}
</style>
